import { Controller } from 'egg';

class SettingController extends Controller {
    /**
     * 查询系统设置
     */
    public async searchAllSetting() {
        const { ctx } = this;
        const SettingData = await this.ctx.service.settingService.searchAllSetting();
        ctx.body = { code: 1, msg: '查询成功', data: SettingData };
    }

    /**
     * 更新系统设置
     */
    public async updateSetting() {
        const { ctx, ctx: { request } } = this;
        const settingData = request.body.data;
        let param: any = [];
        try {
            param = JSON.parse(settingData);
        } catch (e) {
            ctx.body = this.ctx.helper.responseErrorParam('字符串格式错误');
            return;
        }
        await this.ctx.service.settingService.updateSetting(param);
        ctx.body = { code: 1, msg: '更新成功' };
    }
}

export default SettingController;